package com.gitee.melin.bee.util;

import com.hubspot.jinjava.Jinjava;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws Exception {
        Map<String, Object> context = new HashMap<>();
        context.put("name", "test");

        String template = "{% set payment_methods = [\"bank_transfer\", \"credit_card\", \"gift_card\"] %}\n" +
                "\n" +
                "select\n" +
                "    order_id,\n" +
                "    {% for payment_method in payment_methods %}" +
                "    sum(case when payment_method = '{{payment_method}}' then amount end) as {{payment_method}}_amount,\n" +
                "    {% endfor %}" +
                "    sum(amount) as total_amount\n" +
                "from app_data.payments\n" +
                "group by 1";
        Jinjava jinjava = new Jinjava();

        System.out.println(jinjava.render(template, context));
    }
}
